<template>
	<view>
		<view class="address-box">
			<!-- 选择收货地址的盒子 -->
			<view class="address-choose-box" v-if="address.length == 0">
				<button type="success" size="mini" class="btnChooseAddress" @click="getAddress">请选择收货地址+</button>
			</view>

			<!-- 渲染收货信息的盒子 -->
			<view class="address-info-box" v-else>

				<view class="row1">
					<view class="row1-left">
						<view class="username">收货人：<text>{{address[0].userName}}</text></view>
					</view>
					<view class="row1-right">
						<view class="phone">电话：<text>{{address[0].telNumber}}</text></view>
						<uni-icons type="arrowright" size="16"></uni-icons>
					</view>
				</view>
				<view class="row2">
					<view class="row2-left">收货地址：</view>
					<view class="row2-right">{{address[0].provinceName}} {{address[0].cityName}} {{address[0].countyName}}
						{{address[0].detailInfo}}
					</view>
				</view>

			</view>
			<u-line color="#2979ff"></u-line>
		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex"
	export default {
		name: "myAddress",
		data() {
			return {

		
			};
		},
		computed: {
			...mapState("address", ["address"])
		},
		methods: {
			...mapMutations("address", ["addAddress"]),
			// 调用此方法，重新发起收货地址的授权
			getAddress() {
				uni.getSetting({
					success: (res) => {
						if (!res.authSetting['scope.address']) {
							uni.authorize({
								scope: 'scope.address',
								success: (res) => {
									uni.$showToast('地址授权成功')
									// 用户已经同意小程序使用录音功能，后续调用 uni.startRecord 接口不会弹窗询问
									uni.chooseAddress({
										success: (res) => {
	
											this.addAddress(res)
											this.addr = this.address
										}
									})
								},
								fail: (err) => {
									uni.$showToast('您取消了地址授权！', "error")
								}
							})
						} else {
							uni.chooseAddress({
								success: (res) => {
			
									this.addAddress(res)
									this.addr = this.address
								}
							})
						}
					},
					fail: (err) => {
						uni.$showToast('您取消了地址授权！', "error")
					}
				})
			},


		}



	}
</script>

<style lang="scss" scoped>
	.address-box {
		height: 180rpx;
		// border: 1px solid red;

		.address-choose-box {
			height: 180rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.btnChooseAddress {
				background-color: #1aad19;
				color: #fff;
			}

		}
	}

	// 渲染收货信息的盒子
	.address-info-box {
		font-size: 24rpx;
		height: 180rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: 0 10px;

		// 第一行
		.row1 {
			display: flex;
			justify-content: space-between;

			.row1-right {
				display: flex;
				align-items: center;

				.phone {
					margin-right: 10rpx;
				}
			}
		}

		// 第二行
		.row2 {
			display: flex;
			align-items: center;
			margin-top: 20rpx;

			.row2-left {
				white-space: nowrap;
			}
		}
	}
</style>